
package cn.pconline.autoclub.service.ucsysnc;

import org.springframework.beans.factory.annotation.Autowired;

import cn.pconline.autoclub.entity.User;
import cn.pconline.autoclub.mq.AbstractMessageHandler;
import cn.pconline.autoclub.service.UserService;
import cn.pconline.autoclub.util.Regex;

import com.alibaba.fastjson.JSONObject;

import java.util.Date;

/**
 *
 * @author ppc
 */
public class SyncUserInfoService extends AbstractMessageHandler{
    @Autowired
    private UserService userService;
    @Override
    public void handleJsonMessage(JSONObject object) {
    	
        long userId = object.getLong("userId");
        User user =  userService.findUser(userId);
        if(user!=null){
           user.setTruename(object.getString("realName")); 
           //个人中心1代表男 2代表女,车友会0代表男,1代表女
           user.setGender(object.getIntValue("gender")==1?0:1);
           long birthday = object.getLongValue("birthday");
           if(birthday!=0){
               user.setBirthday(new Date(birthday));
           }else{
               user.setBirthday(null);
           }
           user.setProvinceId(object.getLongValue("provinceCode"));
           user.setProvince(object.getString("provinceName"));
           user.setCityId(object.getLongValue("cityCode"));
           user.setCity(object.getString("cityName"));
           user.setEmail(object.getString("email"));
           String ucPhone = object.getString("telephone");
           //判断是否为手机号或固话号，是则同步，否则不同步
           if(ucPhone.matches(Regex.cellphone.value) || ucPhone.matches(Regex.telephone.value)) {    
        	   user.setUcPhone(ucPhone);
           }
           userService.updateUser(user);
        }
    }
}